

package com.kingcore.director.resourcemaster.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Event;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

import org.apache.log4j.Logger;

import wzw.beans.CodeNameBean;
import wzw.beans.DbBean;
import wzw.sql.DatabaseOperator;
import wzw.swing.table.PlainTable;
import wzw.swing.table.PlainTableModel;
import wzw.util.ComponentUtil;
import wzw.util.I18nUtil;
import wzw.util.I18nUtils;
import wzw.util.StringUtils;

import com.kingcore.director.DirectorConstants;
import com.kingcore.director.base.ui.DirectorPanel;
import com.kingcore.director.core.ui.CommonSearchPanel;
import com.kingcore.director.core.ui.CommonSearchable;
import com.kingcore.director.core.ui.ProcessingDialog;
import com.kingcore.director.core.util.DirectorFileUtils;
import com.kingcore.director.main.Main;
import com.kingcore.director.main.MainFrame;
import com.kingcore.director.setting.bean.FilesCopyBean;
import com.kingcore.framework.context.ApplicationContext;
import com.sunking.swing.JDirChooser;
import com.sunking.swing.JFileTree;
import com.sunking.swing.JFileTree.AllFileFilter;
import com.sunking.swing.JTreeComboBox;

/**
 * @author Zeven
 *
 */
public class FileCopyMainPanel extends DirectorPanel
	implements DatabaseOperator,
				CommonSearchable,
				ItemListener,
				ActionListener,
				MouseListener,
				KeyListener {

	/** 
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel mainTopPanel = null;
	private JLabel lbl_lb = null;
	private JLabel lbl_dist = null;
	private JLabel lbl_type = null;
	private JLabel lbl_file = null;
	private JComboBox lbbh = null;
	private JComboBox cptype = null;
	private JTextField destPath = null;
	private JButton btnCopy = null;
	private JScrollPane mainScrollPane = null;
	private PlainTable mainTable = null;
	private JButton btnAdd = null;
	private JButton btnDel = null;
	private JComboBox path = null;

	Logger log = Logger.getLogger(FileCopyMainPanel.class);
	private JButton btnSaveLb = null;
	private JButton btnChoose = null;
	private JPopupMenu popupMenuForTable = null;	//JTable 的 JPopupMenu
	private JMenuItem jpmi_MainTable_Useful;
	private JMenuItem jpmi_MainTable_Delete;
	private JMenuItem jpmi_MainTable_Search;
	private JMenuItem jpmi_MainTable_Execute;
	private JMenuItem jpmi_MainTable_Execute_FX;	//反向复制
	private JMenuItem jpmi_MainTable_Execute_Del_Content;	//反向删除
	private JMenuItem jpmi_MainTable_Execute_Del_Content_FX;	//反向删除
	private JMenuItem jpmi_MainTable_ExecuteAll;
	private JMenuItem jpmi_MainTable_ExecuteAll_FX;	//反向复制
	private JMenuItem jpmi_MainTable_Execute_Path_Copy;	//复制路径
	private JMenuItem jpmi_MainTable_CreatePath;  //创建文件夹
	private JMenuItem jpmi_MainTable_Open;  //open file or path
	private JMenuItem jpmi_MainTable_OpenPath;  //open file or path
	private JMenuItem jpmi_MainTable_OpenBackup;   //打开复制的备份
	private JButton btnCopyRev = null;
	

	//------------------------------ MainTable Begin -----------------
	private static final int MainTable_Column_Index_IsUseful = 0;
	private static final int MainTable_Column_Index_Uri = 1;
	private static final int MainTable_Column_Index_Type = 2; //1:Folder;2:File
	
	private static final int MainTable_Column_Count = 3;
		
	public static final String[] MainTable_Headers = {"启用否", "文件路径", "类型"};
	public static final int[] MainTable_Columns_Width = {80, Main.MainFrame_Size_Width-80-70, 70};
	
	
	/**
	 * This method initializes lbbh	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getLbbh() {
		if (lbbh == null) {
			lbbh = new JComboBox();
			lbbh.setBounds(new java.awt.Rectangle(90,8,185,25));
			//lbbh.addContainerListener( this );
			lbbh.addItemListener( this );
		}
		return lbbh;
	}

	/**
	 * This method initializes cptype	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getCptype() {
		if (cptype == null) {
			cptype = new JComboBox();
			cptype.setBounds(new java.awt.Rectangle(352,39,117,25));
			ComponentUtil.initComboBox( cptype,new String[][]{{"1","硬盘到硬盘"},{"2","硬盘到移动盘"},{"3","移动盘到硬盘"}} );
			cptype.setSelectedIndex(2) ;
		}
		return cptype;
	}

	/**
	 * This method initializes destPath	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JTextField getDestPath() {  //复制目标位置
		if (destPath == null) {
			destPath = new JTextField();	//JComboBox
			destPath.setBounds(new java.awt.Rectangle(90,39,156,25));
			//((JTreeComboBox)destPath).setTree(new JFileTree());
			destPath.setEditable(false);
		}
		return destPath;
	}

	/**
	 * This method initializes btnCopy	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnCopy() {
		if (btnCopy == null) {
			btnCopy = new JButton();
			btnCopy.setBounds(new java.awt.Rectangle(380,8,70,27));
			btnCopy.setText("复制");
			btnCopy.addActionListener( this );
		}
		return btnCopy;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getMainScrollPane() {
		if (mainScrollPane == null) {
			mainScrollPane = new JScrollPane();
			//jScrollPane.setBounds(new java.awt.Rectangle(12,105,470,338));
			mainScrollPane.setViewportView(getMainTable());
		}
		return mainScrollPane;
	}

	/**
	 * This method initializes table	
	 * 	
	 * @return javax.swing.JTable	
	 */
	private PlainTable getMainTable() {
		if (mainTable == null) {
			mainTable = new PlainTable();
			DefaultTableModel dtm = new DefaultTableModel(1,2);
			PlainTableModel sorter = new PlainTableModel( dtm, mainTable.getTableHeader());
		    
			mainTable.setModel( sorter );
			mainTable.setEnabled(true);
			mainTable.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); //SINGLE_SELECTION
			
			mainTable.setShowGrid(true);
			//tztj.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			mainTable.getTableHeader().setReorderingAllowed(false);
			//mainTable.setForeground(Color.blue);
			(mainTable.getModel()).getTableModel().setColumnIdentifiers( MainTable_Headers );

//			table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
			//table.getColumn("是否启用").setWidth(50);
			//table.getModel().getColumnName(0).
			//table.getColumnModel().getColumn(0).setWidth( 10 );
			//table.getColumn("是否启用").setPreferredWidth( 50 );
			for (int i = 0; i < MainTable_Column_Count; i++) {
				mainTable.getColumnModel().getColumn(i).setPreferredWidth( MainTable_Columns_Width[i] );
			}
			//table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
			mainTable.addMouseListener( this );
			mainTable.addKeyListener(this);
		}
		return mainTable;
	}

	/**
	 * This method initializes btnAdd	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnAdd() {
		if (btnAdd == null) {
			btnAdd = new JButton();
			btnAdd.setBounds(new java.awt.Rectangle(279,69,82,27));
			btnAdd.setText("增加");
			btnAdd.addActionListener( this );
		}
		return btnAdd;
	}

	/**
	 * This method initializes btnDel	
	 * 
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnDel() {
		if (btnDel == null) {
			btnDel = new JButton();
			btnDel.setBounds(new java.awt.Rectangle(372,69,79,27));
			btnDel.setText("删除");
			btnDel.addActionListener( this );
		}
		return btnDel;
	}

	/**
	 * This method initializes path	,
	 * Zeven on 2007-03-21, add AllFileFilter not only Directory.
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getPath() {
		if (path == null) {
			path = new JTreeComboBox();	//JComboBox();
			path.setBounds(new java.awt.Rectangle(90,70,185,23));
			((JTreeComboBox)path).setTree(new JFileTree( new AllFileFilter()));
		}
		return path;
	}

	/**
	 * This method initializes btnSaveLb	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnSaveLb() {
		if (btnSaveLb == null) {
			btnSaveLb = new JButton();
			btnSaveLb.setBounds(new java.awt.Rectangle(279,8,100,27));
			btnSaveLb.setText("保存设置");
			btnSaveLb.addActionListener( this );
		}
		return btnSaveLb;
	}

	/**
	 * This method initializes btnChoose	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnChoose() {
		if (btnChoose == null) {
			btnChoose = new JButton();
			btnChoose.setBounds(new java.awt.Rectangle(248,39,27,24));
			btnChoose.setText("...");
			btnChoose.addActionListener( this );
		}
		return btnChoose;
	}

	/**
	 * This method initializes btnCopyRev	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnCopyRev() {
		if (btnCopyRev == null) {
			btnCopyRev = new JButton();
			btnCopyRev.setBounds(new java.awt.Rectangle(455,8,88,27));
			btnCopyRev.setText("反向复制");
			btnCopyRev.addActionListener( this );
		}
		return btnCopyRev;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

//	/**
//	 * This is the default constructor
//	 */
//	public FileCopyPanel() {
//		this(null);
//	}

	public FileCopyMainPanel(MainFrame mainFrame) {
		super(mainFrame); 
		initializeInterface();
		this.update(null, null);
		try {
			fetchData();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		constructAfter();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initializeInterface() {
		this.setLayout( new BorderLayout() );
		this.add( getMainSplitPane(), BorderLayout.CENTER);
		this.add( getStatusBar(true), BorderLayout.SOUTH);
		this.addKeyListener(this);
	}

	private static int MainSplitPane_Top_Height = 105;
	private JSplitPane mainSplitPane = null;
	protected JSplitPane getMainSplitPane(){
		if (mainSplitPane==null) {
			mainSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false);
			mainSplitPane.add(getMainTopPanel(),0);
			mainSplitPane.add(getBottomSplitPane(),1);
			mainSplitPane.setOneTouchExpandable(false);
			mainSplitPane.setDividerSize(0);
			mainSplitPane.setDividerLocation( MainSplitPane_Top_Height );  //200);
		}
		return mainSplitPane;
	}

//	JPanel bottomSplitPane = null;
//	private JPanel getBottomSplitPane() {
//		if(bottomSplitPane==null){
//			bottomSplitPane = new JPanel();
//			bottomSplitPane.setLayout( new BorderLayout() );	
//			bottomSplitPane.add(getCommonSearchPanel(), BorderLayout.SOUTH );	
//			bottomSplitPane.add(getMainScrollPane(), JSplitPane.BOTTOM );
//		}
//		return bottomSplitPane;
//	}
	
	JSplitPane bottomSplitPane = null;
	private JSplitPane getBottomSplitPane() {
		if(bottomSplitPane==null){
			bottomSplitPane = new JSplitPane();

			bottomSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false);
			bottomSplitPane.setBorder(null);	
			bottomSplitPane.add(getCommonSearchPanel(), JSplitPane.TOP );	
			bottomSplitPane.add(getMainScrollPane(), JSplitPane.BOTTOM );
			bottomSplitPane.setOneTouchExpandable(false);
			bottomSplitPane.setDividerSize(0);
			bottomSplitPane.setDividerLocation( CommonSearchPanel_Hight ); //Main.MainFrame_Size_Height-180
			
		}
		return bottomSplitPane;
	}

	private CommonSearchPanel searchPanel = null;
	private CommonSearchPanel getCommonSearchPanel() {

		if(searchPanel==null){
			searchPanel = new CommonSearchPanel(this, this.getMainTable() );
			this.mainFrame.getLanguageManager().addObserver(searchPanel);
		}
		return searchPanel;
	}
	
	@Override
	public void refreshView() {
		super.refreshView();
		
		this.getLbbh().requestFocusInWindow();
		setStatus(StatusBar_Index_One, currentStatusInfor);
	}
	
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getMainTopPanel() {
		if (mainTopPanel == null) {
			lbl_file = new JLabel();
			lbl_file.setBounds(new java.awt.Rectangle(28,70,74,23));
			lbl_file.setText(" 文件(夹)：");
			lbl_type = new JLabel();
			lbl_type.setBounds(new java.awt.Rectangle(290,40,70,23));
			lbl_type.setText("复制类型：");
			lbl_dist = new JLabel();
			lbl_dist.setBounds(new java.awt.Rectangle(28,40,90,23));
			lbl_dist.setText("复制目标：");
			lbl_lb = new JLabel();
			lbl_lb.setBounds(new java.awt.Rectangle(28,9,90,23));
			lbl_lb.setText("复制类别：");
			mainTopPanel = new JPanel();
			mainTopPanel.setBorder( new LineBorder( Color.GRAY ) );
			mainTopPanel.setLayout(null);
			mainTopPanel.add(lbl_lb, null);
			mainTopPanel.add(lbl_dist, null);
			mainTopPanel.add(lbl_type, null);
			mainTopPanel.add(getLbbh(), null);
			mainTopPanel.add(getCptype(), null);
			mainTopPanel.add(getDestPath(), null);
			mainTopPanel.add(getBtnCopy(), null);
			mainTopPanel.add(getBtnAdd(), null);
			mainTopPanel.add(getBtnDel(), null);
			mainTopPanel.add(getPath(), null);
			mainTopPanel.add(lbl_file, null);
			mainTopPanel.add(getBtnSaveLb(), null);
			mainTopPanel.add(getBtnChoose(), null);
			mainTopPanel.add(getBtnCopyRev(), null);
		}
		return mainTopPanel;
	}


	/**
	 * Table的弹出式菜单
	 */
	private JPopupMenu getPopupMenuForTable(){
		
		if(popupMenuForTable == null){
			popupMenuForTable = new JPopupMenu();

			jpmi_MainTable_Search = new JMenuItem();
			jpmi_MainTable_Search.setText("Find in current list");
			jpmi_MainTable_Search.addActionListener( this );
			jpmi_MainTable_Search.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_F,Event.CTRL_MASK) );
			
			jpmi_MainTable_Useful = new JMenuItem();
			jpmi_MainTable_Useful.setText("设置为无效");
			jpmi_MainTable_Useful.addActionListener( this );
			jpmi_MainTable_Useful.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_M,Event.CTRL_MASK) );
			
			jpmi_MainTable_Delete = new JMenuItem();
			jpmi_MainTable_Delete.setText("删除");
			jpmi_MainTable_Delete.addActionListener( this );
			jpmi_MainTable_Delete.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_D,Event.CTRL_MASK) );
			
			jpmi_MainTable_Execute = new JMenuItem();
			jpmi_MainTable_Execute.setText("执行选中行复制");
			jpmi_MainTable_Execute.addActionListener( this );
			jpmi_MainTable_Execute.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C,Event.CTRL_MASK) );
			
			jpmi_MainTable_Execute_FX = new JMenuItem();
			jpmi_MainTable_Execute_FX.setText("执行选中行的反向复制");
			jpmi_MainTable_Execute_FX.addActionListener( this );
			jpmi_MainTable_Execute_FX.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R,Event.CTRL_MASK) );

			jpmi_MainTable_ExecuteAll = new JMenuItem();
			jpmi_MainTable_ExecuteAll.setText("执行所有行的复制");
			jpmi_MainTable_ExecuteAll.addActionListener( this );
			//jpmi_Table_ExecuteAll.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C,Event.CTRL_MASK) );
			
			jpmi_MainTable_ExecuteAll_FX = new JMenuItem();
			jpmi_MainTable_ExecuteAll_FX.setText("执行所有行的反向复制"); 
			jpmi_MainTable_ExecuteAll_FX.addActionListener( this );
			//jpmi_Table_ExecuteAll_FX.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R,Event.CTRL_MASK) );
			
			jpmi_MainTable_Execute_Del_Content = new JMenuItem();
			jpmi_MainTable_Execute_Del_Content.setText("执行选中行的文件内容删除");
			jpmi_MainTable_Execute_Del_Content.addActionListener( this );
			//jpmi_MainTable_Execute_Del_Content.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_H,Event.CTRL_MASK) );

			jpmi_MainTable_Execute_Del_Content_FX = new JMenuItem();
			jpmi_MainTable_Execute_Del_Content_FX.setText("执行选中行的文件备份内容删除");
			jpmi_MainTable_Execute_Del_Content_FX.addActionListener( this );
			//jpmi_MainTable_Execute_Del_Content_FX.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_H,Event.CTRL_MASK) );
			
			jpmi_MainTable_CreatePath = new JMenuItem();
			jpmi_MainTable_CreatePath.setText("创建选中行的文件夹");
			jpmi_MainTable_CreatePath.addActionListener( this );
			//jpmi_Table_CreatePath.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C,Event.CTRL_MASK) );
			
			jpmi_MainTable_Execute_Path_Copy = new JMenuItem();
			jpmi_MainTable_Execute_Path_Copy.setText("Copy full path"); //复制文件全路径
			jpmi_MainTable_Execute_Path_Copy.addActionListener( this );

			jpmi_MainTable_Open = new JMenuItem();
			jpmi_MainTable_Open.setText("Open");
			jpmi_MainTable_Open.addActionListener( this );

			jpmi_MainTable_OpenPath = new JMenuItem();
			jpmi_MainTable_OpenPath.setText("Open path");
			jpmi_MainTable_OpenPath.addActionListener( this );

			jpmi_MainTable_OpenBackup = new JMenuItem();
			jpmi_MainTable_OpenBackup.setText("Open copy backup");
			jpmi_MainTable_OpenBackup.addActionListener( this );
			
			popupMenuForTable.add( jpmi_MainTable_Search );
			popupMenuForTable.add( jpmi_MainTable_Useful );
			popupMenuForTable.add( jpmi_MainTable_Delete );
			popupMenuForTable.addSeparator();

			popupMenuForTable.add( jpmi_MainTable_Execute );
			popupMenuForTable.add( jpmi_MainTable_Execute_FX );
			popupMenuForTable.addSeparator();
			
			popupMenuForTable.add( jpmi_MainTable_ExecuteAll );
			popupMenuForTable.add( jpmi_MainTable_ExecuteAll_FX );			
			popupMenuForTable.addSeparator();

			popupMenuForTable.add( jpmi_MainTable_Execute_Del_Content );
			popupMenuForTable.add( jpmi_MainTable_Execute_Del_Content_FX );
			popupMenuForTable.addSeparator();
			
			popupMenuForTable.add( jpmi_MainTable_Open );
			popupMenuForTable.add( jpmi_MainTable_OpenPath );
			popupMenuForTable.add( jpmi_MainTable_OpenBackup );
			popupMenuForTable.add( jpmi_MainTable_CreatePath );
			popupMenuForTable.add( jpmi_MainTable_Execute_Path_Copy );
			
		}
		
		return popupMenuForTable;
			
		
	}
	
	/**
	 * implements DatabaseOperator
	 */
	public boolean fetchData() throws SQLException {
		ComponentUtil.initComboBox( lbbh, "Select Val,Txt,isDefault From "+DirectorConstants.SYS_Class+" Where LBBH='000001' Order By Orderby ASC");

		String ts_lbbh = ComponentUtil.getSelectedItemCode( lbbh );
		getDataByLbbh(ts_lbbh);
		
		return true;
	}

	public boolean saveData() throws SQLException {
		// TODO Auto-generated method stub
		return true;
	}

	/**
	 * implements ItemListener
	 * @param e
	 */
	public void itemStateChanged(ItemEvent e) {
		Object src = e.getSource();
		if(src==lbbh){
			String ts_lbbh = ComponentUtil.getSelectedItemCode( lbbh );
			getDataByLbbh(ts_lbbh);
		}
		
	}

	
	/**
	 * 由两者以上调用该方法。
	 * @param ts_lbbh
	 */
	private void getDataByLbbh(String ts_lbbh){

		String sql="Select Useful,Path,Type From "+DirectorConstants.FMT_FileCopy+" Where LBBH='"+ts_lbbh+"' Order By Path ASC";
		log.info( sql );
		ComponentUtil.initTable( mainTable, sql);  //写入原始数据
		
		// update type column
		int rowCount = mainTable.getRowCount();
		Object type = null;
		for (int i = 0; i < rowCount; i++) {
			type = mainTable.getValueAt(i, MainTable_Column_Index_Type);
			CodeNameBean cn = new CodeNameBean(type.toString(), getTypeNameByCode(type.toString()));
			mainTable.setValueAt(cn, i, MainTable_Column_Index_Type);
		}
		currentStatusInfor = StringUtils.replace(this.statusBar_mainTableListInfo, "${count}", mainTable.getRowCount()+"");
		setStatus(StatusBar_Index_One, currentStatusInfor);
		
		sql="Select CPTYPE,DestPath From "+DirectorConstants.FMT_FileCopy_Class+" Where LBBH='"+ts_lbbh+"'";
		Connection conn=null;
		Statement stmt=null;
		ResultSet rs=null;

		String ts_cptype;
		String ts_destPath ;
 
		try {
			conn= ApplicationContext.getInstance().getDataSourceManager().getConnection();
			stmt=conn.createStatement();
			log.info( sql );
			rs=stmt.executeQuery(sql);
			if(rs.next()){

				ts_cptype = rs.getString("CPTYPE");
				ts_destPath =rs.getString("DestPath");
				//System.out.println(" ts_cptype="+ts_cptype +" ts_destPath="+ts_destPath);
				ComponentUtil.setSelectedItemByCode( cptype,  ts_cptype);
				destPath.setText(ts_destPath );	//rs.getString("DestPath")
//				//destPath.setSelectedItem( rs.getString("DestPath") );
//				try {
//					//((JFileTree)((JTreeComboBox)getDestPath()).getTree()).setSelectFile( new File(ts_destPath) ) ;
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
			}

		} catch (SQLException e1) {
			JOptionPane.showMessageDialog(this,e1.getMessage(),this.msgDialog_error,JOptionPane.ERROR_MESSAGE);
			e1.printStackTrace();						
		} finally{
			//释放资源
			try {
				if(rs!=null){
					rs.close();
				}
				if(stmt!=null){
					stmt.close();
				}
				if(conn!=null){
					conn.close();
				}
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		}
	}

	private String getTypeNameByCode(String code) {
		if ( (""+DirectorConstants.File_Type_Folder ).equals(code)) {
			return "文件夹";
		} else if ( (""+DirectorConstants.File_Type_File ).equals(code)) {
			return "文件";
		}
		return null;
	}

	/**
	 * implements ActionListener
	 */
	public void actionPerformed(ActionEvent e) {
		Object src = e.getSource();

		// 添加
		if(src==btnAdd){
			String ts_path = null;
			if( getPath().getSelectedItem()==null ){
				JOptionPane.showMessageDialog(this, this.msgDialog_infoChoosePath); //"请选择路径！"
				path.requestFocus();
				return;
			} else {
				//ts_path = getPath().getSelectedItem().toString();
				ts_path = ((JFileTree)((JTreeComboBox)getPath()).getTree()).getSelectFile().getPath() ;
			}
			try {
				addFile2CurrentFileCopy(ts_path);
				JOptionPane.showMessageDialog(this, this.msgDialog_infoAdd2List, //"已成功添加至复制列表！"
						"Finished",JOptionPane.INFORMATION_MESSAGE);
				
			} catch (Exception ex) {		
				JOptionPane.showMessageDialog(this,ex.getMessage(), this.msgDialog_error,JOptionPane.ERROR_MESSAGE); //"操作失败！"
			
			} finally {
			}
			
		// 删除
		} else if( src==btnDel ||
				   src==jpmi_MainTable_Delete ){
			
			int[] rows = getMainTable().getSelectedRows(); //.getSelectedRow();
			if(rows.length<1){
				JOptionPane.showMessageDialog(this, this.msgDialog_plsSelectRow); //"请选择要删除的行！"
				return ;
			}
			if(JOptionPane.showConfirmDialog(this, StringUtils.replace(this.msgDialog_infoDelete,"${rowSize}",rows.length+""), this.msgDialog_info,JOptionPane.OK_CANCEL_OPTION)//"确认删除选择的["+rows.length+"]行记录吗？"
					!=JOptionPane.OK_OPTION)
				return;
			List<String> sql_list = new ArrayList<String>();
			String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );
			for (int row : rows) {
				String ts_path  = getMainTable().getValueAt( row,1).toString();
				String sql="Delete From "+DirectorConstants.FMT_FileCopy +
								" Where LBBH='"+ts_lbbh+"' "+ 
								  " And PATH ='"+ts_path+"'";
				log.debug( sql );
				sql_list.add(sql);
			}

			DbBean dbBean = new DbBean(DbBean.DefaultPoolName);
			try {
				dbBean.executeBatch( sql_list );
				//for (int row : rows) {
				for (int i = rows.length-1; i > -1 ; i--) {  //删除Jtable，从后往前删
					(mainTable.getModel()).getTableModel().removeRow( rows[i] );
				}
				JOptionPane.showMessageDialog(this,this.msgDialog_infoExecuteSuccess, this.msgDialog_info,JOptionPane.INFORMATION_MESSAGE);
				
			} catch (SQLException e1) {
				JOptionPane.showMessageDialog(this,e1.getMessage(), this.msgDialog_errorDbUpdate,JOptionPane.ERROR_MESSAGE);
				e1.printStackTrace();
				return;
			}
			
		} else if ( src==btnCopy ||
			        src==jpmi_MainTable_ExecuteAll ){

			 if(JOptionPane.showConfirmDialog(this,this.msgDialog_infoConfirmCopyAll, this.msgDialog_info,JOptionPane.OK_CANCEL_OPTION) //"确认复制所有文件，并且确认当前系统时间准确吗？"
			 				!=JOptionPane.OK_OPTION)
			 			return;
			 
			 //启动新线程，实现正忙...提示
			 final Component parent = this;
			 Thread thread = new Thread(){
				 public void run(){
					// 复制文件
					 // FilesCopyBean.setFilePath( System.getProperty(MainFrame.USER_DATA_PATH));
					 try {
						 String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );
						 String ts_cptype= ComponentUtil.getSelectedItemCode( getCptype() );
						// String ts_destPath= ((JFileTree)((JTreeComboBox)getDestPath()).getTree()).getSelectFile().getPath() ;
						 String ts_destPath= getDestPath().getText();
						 //System.out.println("dp=" +ts_destPath);
						 FilesCopyBean.main(new String[]{ts_lbbh,ts_cptype,ts_destPath, "SX", null});
						 JOptionPane.showMessageDialog(parent, msgDialog_infoCopySuccess); //"文件复制成功！" 
					
					 } catch (Exception e1) {
						JOptionPane.showMessageDialog(parent, e1.getMessage() );
						return;
					 }
				 }
			 };
			
			 //放在最后面
			ProcessingDialog.showInstance(this.mainFrame, thread ,
						"正在执行，请等待......");//启动等待提示框线程,能否把现实做为线程，对其他代码改动下？

		} else if ( src==btnCopyRev ||
			        src==jpmi_MainTable_ExecuteAll_FX ){	//反向复制

			 if(JOptionPane.showConfirmDialog(this, this.msgDialog_infoConfirmRecoverAll, this.msgDialog_info,JOptionPane.OK_CANCEL_OPTION)
			 				!=JOptionPane.OK_OPTION)
			 			return;
			 //启动新线程，实现正忙...提示
			 final Component parent = this;
			 Thread thread = new Thread(){
				 public void run(){
					// 复制文件
					 // FilesCopyBean.setFilePath( System.getProperty(MainFrame.USER_DATA_PATH));
					 try {
						 String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );
						 String ts_cptype= ComponentUtil.getSelectedItemCode( getCptype() );
						// String ts_destPath= ((JFileTree)((JTreeComboBox)getDestPath()).getTree()).getSelectFile().getPath() ;
						 String ts_destPath= getDestPath().getText();
						 //System.out.println("dp=" +ts_destPath);
						 FilesCopyBean.main(new String[]{ts_lbbh,ts_cptype,ts_destPath, "FX", null});
						 JOptionPane.showMessageDialog(parent, msgDialog_infoCopySuccess );  
					
					 } catch (Exception e1) {
						JOptionPane.showMessageDialog(parent, e1.getMessage() );
						return;
					 }
				 }
			 };
			 
			//放在最后面
			ProcessingDialog.showInstance(this.mainFrame, thread ,
							"正在执行，请等待......");//启动等待提示框线程,能否把现实做为线程，对其他代码改动下？
				
		
		} else if(src==btnSaveLb){
			String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );
			String ts_cptype = ComponentUtil.getSelectedItemCode( getCptype() );
			//String ts_destPath = ((JFileTree)((JTreeComboBox)getDestPath()).getTree()).getSelectFile().getPath() ;
			String ts_destPath = getDestPath().getText() ;

			if( ts_lbbh==null || ts_lbbh.trim().equals("")){
				JOptionPane.showMessageDialog(this, this.msgDialog_infoNoTypeCode); //
				lbbh.requestFocus();
				return;
			}
			if( ts_cptype==null || ts_cptype.trim().equals("") ){
				JOptionPane.showMessageDialog(this,"请复制的类别！"); 
				cptype.requestFocus();
				return;
			}
			
			if( ts_destPath==null ){
				ts_destPath = "";
			}


			// 先删除，后插入
			String sql;				
			sql="Delete From "+DirectorConstants.FMT_FileCopy_Class+" Where LBBH='"+ts_lbbh+"'";
			log.info( sql );
			DbBean dbBean = new DbBean(DbBean.DefaultPoolName);
			try {
				dbBean.executeUpdate( sql );
			} catch (SQLException e1) {
			}
			
			
			sql="Insert Into "+DirectorConstants.FMT_FileCopy_Class+"(LBBH,DESTPATH,CPTYPE) " +
			"Values('"+ts_lbbh+"','"+ 
					   ts_destPath+"','"+ 
					   ts_cptype+"')";
			log.info( sql );
			try {
				dbBean.executeUpdate( sql );
				JOptionPane.showMessageDialog(this, this.msgDialog_infoExecuteSuccess); //"设置保存成功！"
			} catch (SQLException e1) {
				JOptionPane.showMessageDialog(this,e1.getMessage(), this.msgDialog_errorDbUpdate,JOptionPane.ERROR_MESSAGE); //"数据库操作失败"
				e1.printStackTrace();
				return;
			}
			
		} else if (src==btnChoose ){
	        File f = JDirChooser.showDialog( getLbbh().getParent(), "Please Select directory", true, null,
            "Please Select");
			if(f != null){
				String ts_path = f.getAbsolutePath();
				//ts_path = ts_path.replace("\\","/"); //by wzw:keep as same as File.separator
				if( !ts_path.endsWith(File.separator)){
					ts_path += File.separator;
				}
				getDestPath().setText(  ts_path );
			}			

		} else if (src==jpmi_MainTable_Useful ){

			int ti_rowCnt = getMainTable().getSelectedRowCount();
			if(ti_rowCnt<1) return;

			int[] ti_rows = getMainTable().getSelectedRows();
			String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );
			String ts_useful = getMainTable().getValueAt( ti_rows[MainTable_Column_Index_IsUseful],0).toString();
			ts_useful = (ts_useful.equals("Y"))?"N":"Y";
			
			String ts_path = null;
			String ts_sql= null;
			List<String> ls_sqls = new ArrayList<String>();
			for (int ti_row : ti_rows) {
				if(ti_row<0) break;
				ts_path = getMainTable().getValueAt( ti_row,1).toString() ;
				ts_sql="Update "+DirectorConstants.FMT_FileCopy+" Set USEFUL='"+ts_useful+"' WHERE LBBH='"+ts_lbbh+"' AND PATH='"+ts_path+"'";
				log.info( ts_sql );
				ls_sqls.add(ts_sql);
			}
			
			try {
				DbBean dbBean = new DbBean(DbBean.DefaultPoolName);
				dbBean.executeBatch( ls_sqls );
				for (int ti_row : ti_rows) {
					getMainTable().setValueAt( ts_useful, ti_row, 0);
				}
				JOptionPane.showMessageDialog(this, this.msgDialog_infoExecuteSuccess); //"设置保存成功！"
			} catch (SQLException e1) {
				JOptionPane.showMessageDialog(this,e1.getMessage(), this.msgDialog_error,JOptionPane.ERROR_MESSAGE); //"数据库操作失败"
				e1.printStackTrace();
				return;
			}
		} else if (src==jpmi_MainTable_Execute ){

			int[] ti_rows = getMainTable().getSelectedRows();
			if (ti_rows.length<1) {
				JOptionPane.showMessageDialog(this,this.msgDialog_plsSelectRow); //
				return ;
			}
			 if(JOptionPane.showConfirmDialog(this, this.msgDialog_executeSelected , this.msgDialog_info,JOptionPane.OK_CANCEL_OPTION)
			 				!=JOptionPane.OK_OPTION)
			 			return;

			String ts_paths = "";			
			for (int ti_row : ti_rows) {
				if(ti_row<0) break;
				ts_paths +="'"+ getMainTable().getValueAt( ti_row,1).toString() +"',";
			}
			ts_paths = ts_paths.substring(0, ts_paths.length()-1 );
			final String fts_paths = ts_paths;	
			
			final String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );
			//String ts_useful = getTable().getValueAt( ti_row,0).toString();

			final String ts_cptype= ComponentUtil.getSelectedItemCode( getCptype() );
			final String ts_destPath= getDestPath().getText();
			 //启动新线程，实现正忙...提示
			 final Component parent = this;
			 Thread thread = new Thread(){
				 public void run(){
					// 复制文件
					 // FilesCopyBean.setFilePath( System.getProperty(MainFrame.USER_DATA_PATH));
					 try {
						// String ts_destPath= ((JFileTree)((JTreeComboBox)getDestPath()).getTree()).getSelectFile().getPath() ;
						 //System.out.println("dp=" +ts_destPath);
						 FilesCopyBean.main(new String[]{ts_lbbh, ts_cptype,ts_destPath, "SX", fts_paths });
						 JOptionPane.showMessageDialog(parent, msgDialog_infoExecuteSuccess);
					
					 } catch (Exception e1) {
						JOptionPane.showMessageDialog(parent,  msgDialog_infoExecuteSuccess+"：" + e1.getMessage() ); //文件复制完成，但是有错误
						return;
					 }
				 }
			 };

			//放在最后面
			ProcessingDialog.showInstance(this.mainFrame, thread ,
								"正在执行，请等待......");//启动等待提示框线程,能否把现实做为线程，对其他代码改动下？
				
		} else if (src==jpmi_MainTable_Execute_FX ){

			int[] ti_rows = getMainTable().getSelectedRows();
			if (ti_rows.length<1) {
				JOptionPane.showMessageDialog(this, this.msgDialog_plsSelectRow); //"请选择要反向复制的行！"
				return ;
			}
			 if(JOptionPane.showConfirmDialog(this, this.msgDialog_executeSelected_Fx, this.msgDialog_info,JOptionPane.OK_CANCEL_OPTION)
			 				!=JOptionPane.OK_OPTION)
			 			return;

			String ts_paths = "";			
			for (int ti_row : ti_rows) {
				if(ti_row<0) break;
				ts_paths +="'"+ getMainTable().getValueAt( ti_row,1).toString() +"',";
			}
			ts_paths = ts_paths.substring(0, ts_paths.length()-1 );

			final String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );
			//String ts_useful = getTable().getValueAt( ti_row,0).toString();
			//String ts_path = getTable().getValueAt( ti_row,1).toString();

			final String ts_cptype= ComponentUtil.getSelectedItemCode( getCptype() );
			final String ts_destPath= getDestPath().getText();
			final String fts_paths = ts_paths;
			 //启动新线程，实现正忙...提示
			 final Component parent = this;
			 Thread thread = new Thread(){
				 public void run(){
					// 复制文件
					 // FilesCopyBean.setFilePath( System.getProperty(MainFrame.USER_DATA_PATH));
					 try {
						// String ts_destPath= ((JFileTree)((JTreeComboBox)getDestPath()).getTree()).getSelectFile().getPath() ;
						 //System.out.println("dp=" +ts_destPath);
						 FilesCopyBean.main(new String[]{ts_lbbh,ts_cptype,ts_destPath, "FX", fts_paths });
						 JOptionPane.showMessageDialog(parent, msgDialog_infoExecuteSuccess ); //"文件反向复制成功！"
					
					 } catch (Exception e1) {
						JOptionPane.showMessageDialog(parent, e1.getMessage() );
						return;
					 }
				 }
			 };

			 //放在最后面
			ProcessingDialog.showInstance(this.mainFrame, thread ,
							"正在执行，请等待......");//启动等待提示框线程,能否把现实做为线程，对其他代码改动下？


		} else if (src==jpmi_MainTable_Execute_Del_Content ){	// 删除选中行的文件

			final int[] ti_rows = getMainTable().getSelectedRows();
			if (ti_rows.length<1) {
				JOptionPane.showMessageDialog(this, this.msgDialog_plsSelectRow); //"请选择要删除的行！"
				return ;
			}
			 if(JOptionPane.showConfirmDialog(this, StringUtils.replace(this.msgDialog_sureDeleteSelected,"${rowNum}",ti_rows.length+""), this.msgDialog_info,JOptionPane.OK_CANCEL_OPTION)
			 				!=JOptionPane.OK_OPTION)
			 			return;

			 //启动新线程，实现正忙...提示
			 final Component parent = this;
			 Thread thread = new Thread(){
				 public void run(){
					// 删除文件
					String thisPath = null;
					File tmp_file = null;
					String str_err = "";
					for (int ti_row : ti_rows) {
						if(ti_row<0) break;
						thisPath = getMainTable().getValueAt( ti_row,MainTable_Column_Index_Uri).toString();
						//thisCopyTo = toFolder + thisPath.substring(beginPos).replace(":","").replace("\\","/");
						log.info("需要删除文件["+thisPath+"]!");
						tmp_file = new File(thisPath);
		
						if(tmp_file.exists()){
							try{
								org.apache.commons.io.FileUtils.forceDelete(tmp_file);	//.delete()
								log.info("删除文件["+thisPath+"]成功!");
							
							}catch(Exception e2){
								log.info("删除文件["+thisPath+"]失败!\n"+e2.getMessage() );
								str_err +=thisPath+"\n";
								continue;
							}
						}else{
							str_err +=thisPath+"：不存在!\n";
						}
		
					}
					if( "".equals(str_err) ){	// 完全成功
						JOptionPane.showMessageDialog(parent, msgDialog_infoExecuteSuccess);
					}else{
						JOptionPane.showMessageDialog(parent, msgDialog_infoExecuteSuccess+"：\n"+str_err); //删除文件完成，但是有如下文件删除失败
					}
				 }
			 };
			
			//放在最后面
			ProcessingDialog.showInstance(this.mainFrame, thread ,
							"正在执行，请等待......");//启动等待提示框线程,能否把现实做为线程，对其他代码改动下？
			

		} else if (src==jpmi_MainTable_Execute_Del_Content_FX ){	// 删除选中行的备份信息

			final int[] ti_rows = getMainTable().getSelectedRows();
			if (ti_rows.length<1) {
				JOptionPane.showMessageDialog(this, this.msgDialog_plsSelectRow);
				return ;
			}
			 if(JOptionPane.showConfirmDialog(this, StringUtils.replace(this.msgDialog_sureDeleteSelectedBk,"${rowNum}",ti_rows.length+""), this.msgDialog_info,JOptionPane.OK_CANCEL_OPTION)  //
			 				!=JOptionPane.OK_OPTION)
			 			return;

			 //启动新线程，实现正忙...提示
			 final Component parent = this;
			 Thread thread = new Thread(){
				 public void run(){
					String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );
					String ts_cptype= ComponentUtil.getSelectedItemCode( getCptype() );
					String ts_destPath= getDestPath().getText();
					// 删除文件
					String toFolder  =ts_destPath; //.replace("\\","/"); //by wzw:keep as same as File.separator
					String thisCopyTo = null;
					String thisPath = null;
					File tmp_file = null;
					int beginPos = 0;
					String str_err = "";
					for (int ti_row : ti_rows) {
						if(ti_row<0) break;
						thisPath = getMainTable().getValueAt( ti_row,1).toString();
						thisCopyTo = toFolder + thisPath.substring(beginPos).replace(":",""); //.replace("\\","/"); //by wzw:keep as same as File.separator
						log.info("需要删除文件["+thisCopyTo+"]!");
						tmp_file = new File(thisCopyTo);
		
						if(tmp_file.exists()){
							try{
								org.apache.commons.io.FileUtils.forceDelete(tmp_file);	//.delete()
								log.info("删除文件["+thisCopyTo+"]成功!");
							
							}catch(Exception e2){
								log.info("删除文件["+thisCopyTo+"]失败!\n"+e2.getMessage() );
								str_err +=thisCopyTo+"\n";
								continue;
							}
						}else{
							str_err +=thisCopyTo+"：不存在!\n";
						}
		
					}
					if( "".equals(str_err) ){	// 完全成功
						JOptionPane.showMessageDialog(parent,  msgDialog_infoExecuteSuccess); //"删除文件成功!"
					}else{
						JOptionPane.showMessageDialog(parent, msgDialog_infoExecuteSuccess+"：\n"+str_err);
					}
				 }
			 };
			
			//放在最后面
			ProcessingDialog.showInstance(this.mainFrame, thread ,
							"正在执行，请等待......");//启动等待提示框线程,能否把现实做为线程，对其他代码改动下？
			

		} else if (src==jpmi_MainTable_CreatePath ){	// create selected path

			int[] ti_rows = getMainTable().getSelectedRows();
			if (ti_rows.length<1) {
				JOptionPane.showMessageDialog(this, this.msgDialog_plsSelectRow);
				return ;
			}
			 if(JOptionPane.showConfirmDialog(this, StringUtils.replace(this.msgDialog_createSelectedFolder,"${rowNum}",ti_rows.length+""), this.msgDialog_info,JOptionPane.OK_CANCEL_OPTION)
			 				!=JOptionPane.OK_OPTION)
			 			return;

			String ts_path = ""; 
			 // FilesCopyBean.setFilePath( System.getProperty(MainFrame.USER_DATA_PATH));
			 try {		
				 File file = null;
				 Object type = null;
				 String code = null;
				 for (int ti_row : ti_rows) {
					 if(ti_row<0) break;
					 ts_path = getMainTable().getValueAt( ti_row, MainTable_Column_Index_Uri).toString() ;
					 type = getMainTable().getValueAt( ti_row, MainTable_Column_Index_Type);
					 file = new File(ts_path);
					 if (file.exists()) {
						 continue;
					 }else if( type instanceof CodeNameBean ){
						code = ((CodeNameBean)type).getCode();
						if ( (""+DirectorConstants.File_Type_File ).equals(code)) { // 如果是文件则取消创建，避免创建的空文件复制时覆盖真正有内容的文件，即文件建议手动创建
							 /// file.createNewFile();
							 log.warn("ignore : creating file "+ts_path + ".");
						} else {
							 file.mkdirs();
							 log.info("create folder : "+ts_path + " successfully.");
						}
					 }else{
						 log.warn("ignore : unknown file type for "+ts_path + ".");
					 }
				 }
				 JOptionPane.showMessageDialog(this, this.msgDialog_infoExecuteSuccess );
			
			 } catch (Exception e1) {
				JOptionPane.showMessageDialog(this, this.msgDialog_infoExecuteSuccess+"：" + e1.getMessage() );
				return;
			 }


		} else if (src==jpmi_MainTable_Execute_Path_Copy ){	// 复制文件全路径

			int[] ti_rows = getMainTable().getSelectedRows();
			for (int ti_row : ti_rows) {
				if(ti_row<0) break;
				String thisPath = getMainTable().getValueAt( ti_row,1).toString();
				Clipboard system = Toolkit.getDefaultToolkit().getSystemClipboard();
				StringSelection stsel = new StringSelection( thisPath );
				system.setContents(stsel,null);
			}

		} else if (src==jpmi_MainTable_Open ){	// Open file
			openFileOrFolder(false);

		} else if (src==jpmi_MainTable_OpenPath ){	// Open path
			openFileOrFolder(true);

		} else if (src==jpmi_MainTable_OpenBackup ){	// Open backup file

			File file = null;
			int[] ti_rows = getMainTable().getSelectedRows();
			for (int ti_row : ti_rows) {
				if(ti_row<0) break;
				String thisPath = getMainTable().getValueAt( ti_row,1).toString();
				
				thisPath = getBackupFilePath(thisPath);

				file = new File(thisPath);
				if (file.exists()) {
					DirectorFileUtils.openFileQuietly(thisPath);
				}
			}

		} else if( src == jpmi_MainTable_Search){
			this.getBottomSplitPane().setDividerLocation(CommonSearchable.CommonSearchPanel_Hight);
			this.getCommonSearchPanel().getKeywordTextField().requestFocusInWindow();
			//e.consume();
		}
		
	} 
	
	private void openFileOrFolder(boolean isOpenLocation) {
		int[] ti_rows = getMainTable().getSelectedRows();
		File file = null;
		for (int ti_row : ti_rows) {
			if(ti_row<0) break;
			String thisPath = getMainTable().getValueAt( ti_row,1).toString();
			file = new File(thisPath);
			if (file.exists()) {
				if(isOpenLocation){
					DirectorFileUtils.openFileLocationQuietly( thisPath );
				}else{
					DirectorFileUtils.openFileQuietly( thisPath );
				}
			}
		}
	}

	/**
	 * 根据当前文件/目录，计算备份的文件/目录
	 * @param thisPath
	 * @return
	 */
	private String getBackupFilePath(String thisPath) {
		//检查参数
		if(thisPath==null)
			return null;
		String destPath = getDestPath().getText();
		if(StringUtils.isEmpty(destPath))
			return null;
		
		//转换参数
		thisPath = StringUtils.replace(thisPath, ":", ""); //eg: D:\Program\eclipse
		if (destPath.endsWith(File.separator)==false) {
			destPath += File.separator;
		}
		
		//计算结果并返回
		return destPath + thisPath;
	}

	public void addFile2CurrentFileCopy(String fileUri) throws Exception {
		String ts_lbbh = ComponentUtil.getSelectedItemCode( getLbbh() );

		if( ts_lbbh==null || ts_lbbh.trim().equals("")){
			throw new Exception( this.msgDialog_infoNoTypeCode); //"没有设置类别编号！"
		}
		if (fileUri==null) {
			return;
		}
		
		int type = 0;  // 0:folder;1:file;
		File file = new File(fileUri);
		if (file.isFile()) {
			type = 1;
		}
		
		DbBean dbBean = new DbBean(DbBean.DefaultPoolName);
		String sql="select count(0) from "+DirectorConstants.FMT_FileCopy +
				" where lbbh='"+ts_lbbh+"'" +
				   " And path='"+fileUri+"'";
		int cnt = dbBean.queryForInt(sql);
		if (cnt>0) {  // data exists.
			log.info( fileUri+ " already exists. finished!");
			return ;
		}
		
		sql = "Insert Into "+DirectorConstants.FMT_FileCopy+"(LBBH,USEFUL,PATH,Type)" +
				" Values('"+ts_lbbh+"','Y','"+ 
				   fileUri+"',"+type+")";
		log.info( sql );
		dbBean.executeUpdate( sql );
		Vector<Object> v_row = new Vector<Object>();
		v_row.add("Y");
		v_row.add(fileUri);
		v_row.add(new CodeNameBean(type+"", getTypeNameByCode(type+"")));
		(mainTable.getModel()).getTableModel().addRow(v_row);	
	}

	/**
	 * implements MouseListener
	 * @param e
	 */
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseReleased(MouseEvent e) {
		Object obj = e.getSource() ;
		if(obj==getMainTable()){
			// 在Table上右击鼠标
			int ti_row = getMainTable().getSelectedRow();
			if(ti_row<0) return;
			
			String ts_useful = getMainTable().getValueAt( ti_row,0).toString();

			if( e.getButton() == MouseEvent.BUTTON3 ) {	//显示弹出菜单
				
				//System.out.println (getTable().getX()+e.getX());
				//getPopupMenuForTable().locate( getTable().getX()+e.getX(), getTable().getY()+e.getY() );
				//getPopupMenuForTable().setVisible( true );
				getPopupMenuForTable().setSelected(null);

				ResourceBundle bundle = I18nUtils.getBundle(DirectorConstants.I18n_Language_Name);
				if(ts_useful.equals("Y")){
					jpmi_MainTable_Useful.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Useful_N.Text") );
				} else if(ts_useful.equals("N")){
					jpmi_MainTable_Useful.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Useful_Y.Text"));
				} else {
					return ;
				}
				
				getPopupMenuForTable().show( e.getComponent(), e.getX(), e.getY() );
				
			}
		}
		
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	private String msgDialog_infoAdd2List = null;
	private String msgDialog_infoConfirmCopyAll = null;
	private String msgDialog_infoCopySuccess = null;
	private String msgDialog_infoConfirmRecoverAll = null;
	private String msgDialog_infoNoTypeCode = null;
	private String msgDialog_executeSelected = null;
	private String msgDialog_executeSelected_Fx = null;
	private String 	msgDialog_sureDeleteSelected = null;
	private String msgDialog_sureDeleteSelectedBk = null;
	private String msgDialog_createSelectedFolder = null;
	
	@Override
	public void update(Observable o, Object arg) {
		super.update(o, arg);
		
		ResourceBundle bundle = I18nUtils.getBundle(DirectorConstants.I18n_Language_Name);

		//I18nUtil.getBundleString(bundle, MainFrame.class, "tab.reminderMainPanel.Text")
		lbl_lb.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "lbl_lb.Text"));
		lbl_dist.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "lbl_dist.Text"));
		lbl_type.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "lbl_type.Text"));
		lbl_file.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "lbl_file.Text"));
		btnSaveLb.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "btnSaveLb.Text"));
		//btnChoose.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "btnChoose.Text"));
		btnAdd.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "btnAdd.Text"));
		btnDel.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "btnDel.Text"));
		btnCopy.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "btnCopy.Text"));
		btnCopyRev.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "btnCopyRev.Text"));

		//table
	    Vector<String> columnIdentifiers = new Vector<String>();
	    columnIdentifiers.add(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "table.col00.Text"));
	    columnIdentifiers.add(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "table.col01.Text"));
	    columnIdentifiers.add(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "table.col02.Text"));
	    DefaultTableModel dtm = (this.getMainTable().getModel()).getTableModel();
	    dtm.setColumnIdentifiers(columnIdentifiers);
	    
	    //resize table columns
	    TableColumn tc = null;
	    TableColumnModel tcm = mainTable.getColumnModel(); 
        for(int i=0; i < MainTable_Columns_Width.length-1; i++)   { // ?-1
            tc   =   tcm.getColumn(i);
            tc.setPreferredWidth(MainTable_Columns_Width[i]); 
        }
        this.getMainTable().showZebraCross();
		
        this.getPopupMenuForTable();
        jpmi_MainTable_Search.setText(I18nUtil.getBundleString(bundle, FileExplorerMainPanel.class, "jpmi_MainTable_Search.Text"));
        jpmi_MainTable_Useful.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Useful.Text"));
        jpmi_MainTable_Delete.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Delete.Text"));
        jpmi_MainTable_Execute.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Execute.Text"));
        jpmi_MainTable_Execute_FX.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Execute_FX.Text"));
        jpmi_MainTable_Execute_Del_Content.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Execute_Del_Content.Text"));
        jpmi_MainTable_Execute_Del_Content_FX.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Execute_Del_Content_FX.Text"));
        jpmi_MainTable_ExecuteAll.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_ExecuteAll.Text"));
        jpmi_MainTable_ExecuteAll_FX.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_ExecuteAll_FX.Text"));
        jpmi_MainTable_Execute_Path_Copy.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Execute_Path_Copy.Text"));
        jpmi_MainTable_CreatePath.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_CreatePath.Text"));
        jpmi_MainTable_Open.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_Open.Text"));
        jpmi_MainTable_OpenPath.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_OpenPath.Text"));
        jpmi_MainTable_OpenBackup.setText(I18nUtil.getBundleString(bundle, FileCopyMainPanel.class, "jpmi_MainTable_OpenBackup.Text"));


    	String className = FileCopyMainPanel.class.getName();
    	msgDialog_infoAdd2List = I18nUtil.getBundleString(bundle, className, "msgDialog_infoAdd2List.Message");    
    	msgDialog_infoConfirmCopyAll = I18nUtil.getBundleString(bundle, className, "msgDialog_infoConfirmCopyAll.Message");    
    	msgDialog_infoCopySuccess = I18nUtil.getBundleString(bundle, className, "msgDialog_infoCopySuccess.Message");    
    	msgDialog_infoConfirmRecoverAll = I18nUtil.getBundleString(bundle, className, "msgDialog_infoConfirmRecoverAll.Message");    
    	msgDialog_infoNoTypeCode = I18nUtil.getBundleString(bundle, className, "msgDialog_infoNoTypeCode.Message"); 
    	msgDialog_executeSelected = I18nUtil.getBundleString(bundle, className, "msgDialog_executeSelected.Message");    
    	msgDialog_executeSelected_Fx = I18nUtil.getBundleString(bundle, className, "msgDialog_executeSelected_Fx.Message"); 
    	msgDialog_sureDeleteSelected = I18nUtil.getBundleString(bundle, className, "msgDialog_sureDeleteSelected.Message");
    	msgDialog_sureDeleteSelectedBk = I18nUtil.getBundleString(bundle, className, "msgDialog_sureDeleteSelectedBk.Message");
	    msgDialog_createSelectedFolder = I18nUtil.getBundleString(bundle, className, "msgDialog_createSelectedFolder.Message");
	
	    if (this.mainTable!=null) {
		    this.currentStatusInfor = StringUtils.replace(this.statusBar_mainTableListInfo, "${count}", mainTable.getRowCount()+"");
		}
		
	}

	@Override
	public void closeCommonSearchPanel() {
		this.getBottomSplitPane().setDividerLocation(0);
		this.getMainTable().requestFocusInWindow();
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyPressed(KeyEvent e) {

		Object obj= e.getSource();
		if (e.getKeyCode() == KeyEvent.VK_F && e.isControlDown()
	    		&& (obj== getMainTable() || obj==this
//	    				||obj==locationTextField
//	    				||obj==leftFileTree
	    				    ) ) {
			
			this.getBottomSplitPane().setDividerLocation(CommonSearchable.CommonSearchPanel_Hight);
			this.getCommonSearchPanel().getKeywordTextField().requestFocusInWindow();
			e.consume();
	    	
		}
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}
	
}  //  @jve:decl-index=0:visual-constraint="10,10"
